
import CryptoJS from 'crypto-js';
export function encryptAsDoNet(message) {
    const key = 'd5ew4fd8';
    const keyUtf8 = CryptoJS.enc.Utf8.parse(key);
    const iv = CryptoJS.enc.Utf8.parse(key);

    const encrypted = CryptoJS.DES.encrypt(message, keyUtf8, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });

    let base64Str = encrypted.toString();

    base64Str = base64Str.replace(/\r\n/g, '').replace(/\r/g, '').replace(/\n/g, '');
    base64Str = base64Str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '~');

    return base64Str;
}
// 解密
export function DecryptDoNet(message) {
    message = message.replace(/-/g, "+");
    message = message.replace(/_/g, "/");
    message = message.replace(/~/g, "=");
    const key = 'd5ew4fd8';
    const keyUtf8 = CryptoJS.enc.Utf8.parse(key);
    const iv = CryptoJS.enc.Utf8.parse(key);

    const encrypted = CryptoJS.DES.decrypt(message, keyUtf8, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });

    let base64Str = encrypted.toString(CryptoJS.enc.Utf8);
    return base64Str;
}